package com.unipay.user.api;

import com.unipay.common.result.Result;
import com.unipay.common.utils.AuthContextHolder;
import com.unipay.model.user.Patient;
import com.unipay.user.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Project: yitong_parent
 * @Author: C.yu
 * @Time: 2023-05-25 17:14:03
 * @Desc: TODO
 */
@Api(tags = "就诊人管理api")
@RestController
@RequestMapping("/api/user/patient")
public class PatientApiController {

    @Autowired
    private PatientService patientService;

    @ApiOperation("获取就诊人列表")
    @GetMapping("auth/findAll")
    public Result findAll(HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        List<Patient> patientList = patientService.findAllByUserId(userId);
        System.out.println("patientList: " + patientList);
        return Result.ok(patientList);
    }
    @ApiOperation("添加就诊人")
    @PostMapping("auth/save")
    public Result save(@RequestBody Patient patient, HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        boolean save = patientService.save(patient);
        return Result.ok(save);
    }
    @ApiOperation("修改就诊人信息")
    @PutMapping("auth/update")
    public Result update(@RequestBody Patient patient){
        boolean b = patientService.updateById(patient);
        return Result.ok(b);
    }
    @ApiOperation("根据ID获取就诊人信息")
    @GetMapping("auth/get/{id}")
    public Result get(@PathVariable Long id){
        //Patient patient = patientService.getById(id);
        Patient patient = patientService.get(id);
        return Result.ok(patient);
    }
    @ApiOperation("根据ID输出就诊人信息")
    @DeleteMapping("auth/remove/{id}")
    public Result remove(@PathVariable Long id){
        boolean b = patientService.removeById(id);
        return Result.ok(b);
    }
    @ApiOperation("预约下单获取就诊人")
    @GetMapping("inner/get/{id}")
    public Patient getPatientOrder(
            @ApiParam(name = "id", value = "就诊人ID", required = true)
            @PathVariable("id") Long id
    ){
        return patientService.getById(id);
    }
}
